package com.moon.config;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {
    //定义队列
    @Bean
    public Queue wnQ1(){
        return new Queue("wnQ1");
    }
    @Bean
    public Queue wnQ2(){
        return new Queue("wnQ2");
    }
    @Bean
    public Queue wnQA(){
        return new Queue("wnQA");
    }
    @Bean
    public Queue wnQB(){
        return new Queue("wnQB");
    }
    @Bean
    public Queue DelayQ() {
        return QueueBuilder.durable("DelayQ").withArgument("x-dead-letter-exchange", "dirExchange")
                .withArgument("x-dead-letter-routing-key", "play").withArgument("x-message-ttl", 10000).build();
    }


    //定义交换机
    @Bean
    public FanoutExchange fanoutExchange(){
        return new FanoutExchange("fanExchange");
    }
    @Bean
    public DirectExchange directExchange(){
        return new DirectExchange("dirExchange");
    }


    //定义绑定关系
    @Bean
    public Binding bindwnQ1TofanoutExchange(){
        return BindingBuilder.bind(wnQ1()).to(fanoutExchange());
    }
    @Bean
    public Binding bindwnQ2TofanoutExchange(){
        return BindingBuilder.bind(wnQ2()).to(fanoutExchange());
    }
    @Bean
    public Binding bindwnQAToDirExchange(){
        return BindingBuilder.bind(wnQA()).to(directExchange()).with("work");
    }
    @Bean
    public Binding bindwnQBToDirExchange(){
        return BindingBuilder.bind(wnQB()).to(directExchange()).with("play");
    }

}
